package com.yxb.constant;

import com.yxb.util.CHexConver;

import java.util.Arrays;

public class DataPointValue {

    /**
     * 时间  unix 时间戳
     */
    private int utc;

    /**
     * 体重
     * 带有一位小数点
     * 单位 斤
     */
    private int weight;

    /**
     * 阻抗
     * 单位 欧姆
     */
    private int impedance;

    /**
     * 加密之后的阻抗数据
     */
    private int enCodeImpedance;

    public int getUtc() {
        return utc;
    }

    public void setUtc(int utc) {
        this.utc = utc;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getImpedance() {
        return impedance;
    }

    public void setImpedance(int impedance) {
        this.impedance = impedance;
    }

    public int getEnCodeImpedance() {
        return enCodeImpedance;
    }

    public void setEnCodeImpedance(int enCodeImpedance) {
        this.enCodeImpedance = enCodeImpedance;
    }

    public static DataPointValue  parseStrValue(String value){
        short [] bytes= CHexConver.hexStringToBytes(value);
        final short [] targetBytes = Arrays.copyOfRange(bytes, 3, bytes.length);
        DataPointValue  item = new DataPointValue();
        item.parseByteArray(targetBytes);
        return item;
    }
  
    public void parseByteArray(short [] bytes){
        int b = (bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+bytes[3];
        this.utc= b;
        int c = (bytes[4]<<8)+(bytes[5]);
        this.weight = c;
        int d = (bytes[6]<<8)+(bytes[7]);
        this.impedance = d;
        
        byte[] fs = {(byte) bytes[8],(byte) bytes[9],(byte) bytes[10]};
       // int e = (bytes[8]<<16)+(bytes[9]<<8)+(bytes[10]);
        int e = bytes2Int2(fs);
        this.enCodeImpedance = e ;
    }
    
    

    /**
     * 3转一
     * byte数组转int
     * @param bytes
     * @return
     */
    public static int bytes2Int2(byte[] bytes){
        int value=0;
        value =  ((bytes[0] & 0xff)<<16)|
                ((bytes[1] & 0xff)<<8)|
                (bytes[2] & 0xff);
        return value;
}
}
